﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RooHui.Infrastructure.Entities.Entity;
using RooHui.Tool;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;

namespace RooHui.OA.Biz
{
     public class ProcessDoingHistoryBiz
    {
         public static List<ProcessDoingHistory> GetProcessDoingHistoryList(int projectID)
         {
             try
             {
                 using (Context ctx = new Context())
                 {
                     var data = (from c in ctx.ProcessDoingHistory
                                 join d in ctx.User
                                 on c.DoingUser equals d.UserName
                                 join e in ctx.ProcessDoing.Where(f => f.ProjectID == projectID)
                                 on c.ProcessID equals e.ID
                                 where c.ProjectID == projectID
                                 orderby c.DoingTime descending
                                 select new { c, d.RealName, e })
                               .ToList()
                               .Select(p => new ProcessDoingHistory().Set(p.c).LoadUser(new U_User() {RealName=p.RealName }).LoadProcessDoing(p.e)).ToList();
                     return data;
                 }
                 
             }
             catch (Exception ex)
             {
                 LogHelper.Write(CommonLogger.Web, ex);
             }
             return null;
         }
    }
}
